home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / jazlib.arc / JZINSSTR.C < prev    next >
Text File  |  1988-12-18  |  2KB  |  52 lines

  1. /*
  2. ┌────────────────────────────────────────────────────────────────────────────┐
  3. │jzinsstr.c                                     │
  4. │Insert a string into another string at a given index position.          │
  5. │Note that the starting position is the index, not the character number like │
  6. │in pascal!.                                     │
  7. │Synopsis:                                     │
  8. │   char wstr[255];                                 │
  9. │                                         │
  10. │   strcpy(wstr,"this a test");                                              │
  11. │                                         │
  12. │   jzinsstr(wstr,"is ",5);                                                  │
  13. │                                         │
  14. │   { yields "this is a test" }                                              │
  15. │                                         │
  16. │ (C) JazSoft Software by Jack A. Zucker (301) 794-5950              │
  17. └────────────────────────────────────────────────────────────────────────────┘
  18. */
  19.  
  20. #include <jaz.h>
  21. jzinsstr(fdestin,fsource,fstart)
  22. char *fdestin;
  23. char *fsource;
  24. int fstart;
  25. {
  26.  
  27.   int wdlen,wslen;
  28.   int w,wlen,wpad;
  29.  
  30.   wdlen = strlen(fdestin);    /* get destination string length */
  31.   wslen = strlen(fsource);    /* get source string length */
  32.  
  33.   wlen = min(fstart,wdlen);    /* don't initially point past destin */
  34.  
  35.   wpad = fstart - wlen;     /* get extra length to pad */
  36.  
  37.   for (w = wlen ; w < fstart ; w ++)    /* pad with blanks if neccessary */
  38.     fdestin[w] = ' ';
  39.  
  40.   /* start at end of string and move characters to the right */
  41.   /* draw it out if necessary; It's hard to follow if you don't */
  42.  
  43.   for (w = wdlen + wslen - 1 ; w >= fstart + wslen ; w --)
  44.     fdestin[w] = fdestin[w - wslen];
  45.  
  46.   for (w = 0 ; w < wslen ; w ++)    /* now insert into the dest string */
  47.     fdestin[w+fstart] = *fsource++;
  48.  
  49.   fdestin[wslen+wdlen+wpad] = 0;    /* string is bigger, needs NULL */
  50. }
  51.  
  52.